<!DOCTYPE html>
<html>
<head>
    <title>{$article.post_title}</title>
    <meta name="keywords" content="{$site_info.site_seo_keywords|default=''}"/>
    <meta name="description" content="{$site_info.site_seo_description|default=''}">
    <include file="public@head"/>
    <style>
        .commentbox{
            width: 800px;
            margin: 20px auto;
        }
        .mytextarea {
            width: 100%;
            overflow: auto;
            word-break: break-all;
            height: 100px;
            color: #000;
            font-size: 1em;
            resize: none;
        }
        .comment-list{
            width: 100%;
            margin: 20px auto;
            clear: both;
            padding-top: 20px;
        }
        .comment-list .comment-info{
            position: relative;
            margin-bottom: 20px;
            margin-bottom: 20px;
            border-bottom: 1px solid #ccc;
        }
        .comment-list .comment-info header{
            width: 10%;
            position: absolute;
        }
        .comment-list .comment-info header img{
            width: 100%;
            border-radius: 50%;
            padding: 5px;
        }
        .comment-list .comment-info .comment-right{
            padding:5px 0px 5px 11%;
        }
        .comment-list .comment-info .comment-right h3{
            margin: 5px 0px;
        }
        .comment-list .comment-info .comment-right .comment-content-header{
            height: 25px;
        }
        .comment-list .comment-info .comment-right .comment-content-header span,.comment-list .comment-info .comment-right .comment-content-footer span{
            padding-right: 2em;
            color: #aaa;
        }
        .comment-list .comment-info .comment-right .comment-content-header span,.comment-list .comment-info .comment-right .comment-content-footer span.reply-btn,.send,.reply-list-btn{
            cursor: pointer;
        }
        .comment-list .comment-info .comment-right .reply-list {
            border-left: 3px solid #ccc;
            padding-left: 7px;
        }
        .comment-list .comment-info .comment-right .reply-list .reply{
            border-bottom: 1px dashed #ccc;
        }
        .comment-list .comment-info .comment-right .reply-list .reply div span{
            padding-left: 10px;
        }
        .comment-list .comment-info .comment-right .reply-list .reply p span{
            padding-right: 2em;
            color: #aaa;
        }
    </style>
    <style>
        #article_content img {
            height: auto !important;
            max-width: 100%;
        }

        #article_content {
            word-wrap: break-word;
        }
    </style>
    <hook name="before_head_end"/>
</head>
<body class="body-white">
<include file="public@nav"/>
<div class="container tc-main">
    <div class="row">
        <div class="col-md-9">
            <div class="tc-box article-box">
                <h2>{$article.post_title}</h2>
                <div class="article-infobox">
                    <span>{:date('Y-m-d H:i',$article.published_time)} by {$article.user.user_nickname}</span>
                    <span>
		    			<a href="javascript:;"><i class="fa fa-eye"></i><span>{$article.post_hits}</span></a>
						<a href="{:url('portal/Article/doLike',array('id'=>$article['id']))}" class="js-count-btn"><i
                                class="fa fa-thumbs-up"></i><span class="count">{$article.post_like}</span></a>
						<a href="{:url('user/favorite/add')}"
                           class="js-favorite-btn"
                           data-title="{:base64_encode($article.post_title)}"
                           data-url="{:cmf_url_encode('portal/Article/index',array('id'=>$article['id']))}"
                           data-table="portal_post"
                           data-id="{$article['id']}"
                        >
							<i class="fa fa-star-o"></i>
						</a>
					</span>
                </div>
                <hr>
                <php>
                    $before_content_hook_param=[
                    'object_id'=>$article['id'],
                    'table_name'=>'portal_post',
                    'object_title'=>$article['post_title'],
                    'user_id'=>$article['user_id'],
                    'url'=>cmf_url_encode('portal/Article/index',array('id'=>$article['id'],'cid'=>$category['id'])),
                    'object'=>$article
                    ];
                </php>
                <hook name="before_content" param="before_content_hook_param"/>

                <div id="article_content">
                    {$article.post_content}
                </div>
                <if condition="!empty($article['post_source'])">
                    <div>
                        <b>注：本文转载自{$article.post_source}，转载目的在于传递更多信息，并不代表本网赞同其观点和对其真实性负责。如有侵权行为，请联系我们，我们会及时删除。</b>
                    </div>
                </if>

                <php>
                    $after_content_hook_param=[
                    'object_id'=>$article['id'],
                    'table_name'=>'portal_post',
                    'object_title'=>$article['post_title'],
                    'user_id'=>$article['user_id'],
                    'url'=>cmf_url_encode('portal/Article/index',array('id'=>$article['id'],'cid'=>$category['id'])),
                    'object'=>$article
                    ];
                </php>
                <hook name="after_content" param="after_content_hook_param"/>

                <php>
                    $comment_hook_param=[
                    'object_id'=>$article['id'],
                    'table_name'=>'portal_post',
                    'object_title'=>$article['post_title'],
                    'url'=>cmf_url_encode('portal/Article/index',array('id'=>$article['id'],'cid'=>$category['id'])),
                    'user_id'=>$article['user_id'],
                    ];
                    $comment=hook_one('comment',$comment_hook_param);
                </php>

                <!--评论区-->
                <php>
                    $user_login = cmf_get_current_user();
                </php>
                <div class="commentbox">
                    <div class="article-box">
                        <form class="js-ajax-form" action="{:url('user/Comment/add')}" method="post">
                            <textarea cols="80" rows="50" placeholder="来说点什么吧......" class="mytextarea" id="content" name="content"></textarea>
                            <button id="comment-button" class="js-ajax-submit btn btn-primary pull-right" type="submit" style="margin-top: 10px;">提交评论</button>
                            <input type="hidden" id="city" name="city">
                            <input type="hidden" id="object_id" name="object_id" value="{$article['id']}">
                            <input type="hidden" name="user_id" value="{$user_login['id'] | default=''}">
                            <input type="hidden" name="user_login" value="{$user_login['user_nickname'] | default='匿名'}">
                            <input type="hidden" name="email" value="{$user_login['user_email'] | default=''}">
                            <input type="hidden" name="url" value="http://{$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI']}">
                        </form>
                    </div>
                    <div class="comment-list"></div>
                </div>
            </div>
        </div>
        <div class="col-md-3">
            <div class="tc-box first-box">
                <div class="headtitle">
                    <h2>热门文章</h2>
                </div>
                <div class="ranking">
                    <php>
                        $hot_articles=[];
                    </php>
                    <ul class="list-unstyled">
                        <portal:articles limit="5" order="post.post_hits DESC">
                            <php>$top=$key<3?"top3":"";</php>
                            <li class="{$top}">
                                <i>{$key+1}</i>
                                <a title="{$vo.post_title}"
                                   href="{:url('portal/article/index',array('id'=>$vo['id']))}">
                                    {$vo.post_title}
                                </a>
                            </li>
                        </portal:articles>
                    </ul>
                </div>
            </div>

        </div>

    </div>
</div>
<include file="public@footer_jh"/>
<include file="public@scripts"/>
<hook name="before_body_end"/>
<include file="public@scripts_article_comment"/>
<script type="text/javascript">
    function GetUrlRelativePath()
    {
        var url = document.location.toString();

        if(url.indexOf("#") != -1){
            relUrl = url.split("#")[1];
            return relUrl;
        }else{
            return 0;
        }

    }
    document.getElementById('city').value = returnCitySN['cname']; //获取地址城市
    //接受初始化数据
    var arr = new Array();
    var arr_reple =new Array();
    var object_id = document.getElementById("object_id").value;
    //console.log(object_id);
    $(function(){
        $.ajax({
           // async:false, //开始同步
            global:false,//不启用全局
            type: "GET",
            url: "{:url('user/Comment/reply')}",
            data: {object_id:object_id},
            dataType: "json",
            success: function(data){
                if(data.code==1){
                    //将获取的数据循环压入新的数组中
                    //console.log(data.data.length);
                    for( let i of data.data){
                        if(i['type'] ==1){
                            arr_reple1 = {
                                id: i['floor'],
                                replyName: i['full_name'],
                                beReplyName: i['to_user_name'],
                                content: i['content'],
                                time: i['create_time'],
                                osname: "", //用户使用的系统
                                browse: "", //用户使用的浏览器
                                comm_id: i['id'],
                                url: i['url'],
                                user_id:i['user_id'],
                                replyBody: []
                            };
                            // console.log(i);
                            arr_reple.push(arr_reple1);
                        }else{
                            arr1 = {
                                id: i['floor'],
                                img: i['avatar'],
                                replyName: i['full_name'],
                                beReplyName: "",
                                content: i['content'],
                                time: i['create_time'],
                                address: i['city'],
                                osname: "",
                                browse: "",
                                sex: i['sex'],
                                comm_id: i['id'],
                                url: i['url'],
                                user_id:i['user_id'],
                                replyBody: []
                            },
                                arr.push(arr1);
                            // console.log(i);
                        }
                    }
                    //console.log(arr);
                    //console.log(arr_reple);
                    if(arr_reple !== ''){
                        for (let i of arr_reple){
                            for (let ix of arr) {
                                if(i['id'] == ix['id']){
                                    ix['replyBody'].push(i);
                                    //console.log(ix['replyBody']);
                                }
                            }
                        }
                    }
                    $(".comment-list").addCommentList({data:arr,add:""});
                    $(".comment-info").each(function(){
                        //console.log($(this).attr("name").replace(/[^0-9]/ig,""));
                    });
                    var url_point = '#'+GetUrlRelativePath();
                    //alert(url_point);
                    if(url_point){
                        $('html, body').animate({scrollTop: $(url_point).offset().top}, 1000)
                    }
                }

                if(data.code==0){
                    Wind.use('noty', function () {
                        noty({
                            timeout: 1000,
                            text: data.msg,
                            type: 'confirm',
                            layout: "center",
                            modal: true,
                        });
                    });
                }
            }
        });
    });

</script>
</body>
</html>